<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<#include "/include/head_common.ftl">
	<#include "/include/login_trace.ftl">
	<#assign permissionSet = fm.getPermission() />
	<#assign edit= fm.hasPermission("sql:parameter:edit",permissionSet)/>
	<#assign view= fm.hasPermission("sql:parameter:view",permissionSet)/>
	<#assign disabled = edit?string('','disabled')/>
	<#assign typeMap={"java.lang.Integer","java.lang.Integer",
					  "java.math.BigDecimal","java.math.BigDecimal",
	                  "java.lang.Double":"java.lang.Double",
	                  "java.lang.Long":"java.lang.Long",
	                  "java.lang.Boolean":"java.lang.Boolean",
	                  "java.lang.Character":"java.lang.Character",
	                  "java.util.Date":"java.util.Date",
	                  "java.math.BigInteger":"java.math.BigInteger",
	                  "java.lang.String":"java.lang.String"
	}/>
<title>
	<#if edit>
		SQL参数<#if parameter.id??>修改<#else>添加</#if>
	<#else>
		SQL参数查看
	</#if>
</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
	$(document).ready(
			function() {
				closeTip();
				$("#value").focus();
				$("#inputForm")
						.validate(
								{
									submitHandler : function(form) {
										loading('正在提交，请稍等...');
										form.submit();
									},
									errorContainer : "#messageBox",
									errorPlacement : function(error, element) {
										$("#messageBox").text("输入有误，请先更正。");
										if (element.is(":checkbox")
												|| element.is(":radio")
												|| element.parent().is(
														".input-append")) {
											error.appendTo(element.parent()
													.parent());
										} else {
											error.insertAfter(element);
										}
									}
								});
			});
	function goback(){
    	$.cookie('goback','goback',{path: '/',expires: 1});
    	history.go(-1);
    }

	function formatJson(id) {
		var format = $('#' + id).val().replace(/(^\s*)|(\s*$)/g, "");
		if(format.length > 0){
			$.ajax({
				type: "POST",
				url: "${rootUrl}/sql/json",
				contentType: "application/json;charset=UTF-8",
				dataType: 'json',
				data: format,
				success: function (data) {
					if (!data.isJson) {
						top.$.jBox.tip("非json格式", "error", {
							persistent : true,
							opacity : 0,
							timeout: 500
						});
					}else {
						$('#' + id).val(data.text.replaceAll('\t','\t\t').replaceAll(" ","  "));
					}
				}
			});
		}
	}
	function changeTransform(selectId, textAreaId, textId) {
		var classname = $('#' + selectId).val().replace(/(^\s*)|(\s*$)/g, "");
		if (classname.length > 0) {
			$.ajax({
				type: "GET",
				url: "${rootUrl}/sql/converterParam?classname=" + classname,
				contentType: "application/json;charset=UTF-8",
				dataType: 'json',
				success: function (data) {
					if (data.success) {
						$('#' + textAreaId).val(data.exampleConfig);
						var exampleConfigDesc = data.exampleConfigDesc +"";
						exampleConfigDesc = exampleConfigDesc.replaceAll("\n", "<BR>")
								.replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
								.replaceAll(" ", "&nbsp;&nbsp;");
						$('#' + textId).html(exampleConfigDesc);
					}else {
						$('#' + textAreaId).val('');
						$('#' + textId).html('');
					}
				}
			});
		}
	}
	function resetForm(){
		$("#inputForm")[0].reset();
		$("#parameterFormatDesc").html('不选参数转换类，主要是时间格式化,<BR>选择参数转换类就是构造参数');
	}
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<#if fm.hasPermission("sql:define:view",permissionSet) >
			<li><a href="${rootUrl}/sql/define/list">SQL列表</a></li>
		</#if>
		<#if fm.hasPermission("sql:define:edit",permissionSet) >
			<li><a href="${rootUrl}/sql/define/edit">SQL添加</a></li>
		</#if>
		<#if view >
			<li><a href="${rootUrl}/sql/parameter/list?defineKey=${parameter.defineKey!''}">SQL参数列表</a></li>
		</#if>
		<li class="active">
			<a href="${rootUrl}/sql/parameter/edit?id=${parameter.id!''}">
				<#if edit>
					SQL参数<#if parameter.id??>修改<#else>添加</#if>
				<#else>
					SQL参数查看
				</#if>
			</a>
		</li>
		<#if fm.hasPermission("sql:fieldTransform:view",permissionSet) >
			<li><a href="${rootUrl}/sql/fieldTransform/list">列转换器列表</a></li>
		</#if>
		<#if fm.hasPermission("sql:fieldTransform:edit",permissionSet) >
			<li><a href="${rootUrl}/sql/fieldTransform/edit">列转换器添加</a></li>
		</#if>
	</ul>
	<br />
	<form id="inputForm" action="${rootUrl}/sql/parameter/edit" method="post"
		class="form-horizontal form-signin">
		<input type="hidden" name="id" value="${parameter.id!''}" />
		<div class="control-group">
			<label class="control-label">定义的key:</label>
			<div class="controls">
				<select id="defineKey" name="defineKey" class="input-xxlarge required" <#if !edit> disabled </#if>>
					<option value="">请选择...</option>
					<#list defineList as define>
						<option value="${define.defineKey}"  <#if parameter.defineKey?? && define.defineKey = parameter.defineKey!''> selected </#if> >
							${define.defineKey}(${define.sqlDescribe})
						</option>
					</#list>
				</select>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label">参数名:</label>
			<div class="controls">
				<input name="paramName" value="${parameter.paramName!''}" maxlength="50"
					   class="required"  type="text" ${disabled}/>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">参数类型:</label>
			<div class="controls">
				<select name="paramType" class="required input-large">
					<option value="">请选择...</option>
					<#list typeMap?keys as key>
						<option value="${typeMap[key]}"  <#if parameter.paramType?? && parameter.paramType = typeMap[key]> selected </#if> >${key}</option>
					</#list>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">参数描述:</label>
			<div class="controls">
				<input name="paramDescribe" value="${parameter.paramDescribe!''}" maxlength="50"
					   class="required"  type="text" ${disabled}/>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">参数转换类:</label>
			<div class="controls">
				<select id="paramConverter" name="converter" class="input-xxlarge" ${disabled} style="font-size: 15px; width: 800px;" onchange="changeTransform(this.id,'parameterFormat','parameterFormatDesc')">
					<option value="">请选择...</option>
					<#list converterClassnames as classname>
						<option value="${classname}"  <#if parameter.converter?? && parameter.converter = classname> selected </#if> >${classname}</option>
					</#list>
				</select>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">转换参数格式:</label>
			<div class="controls">
				<textarea id = "parameterFormat" style="font-size: 15px; width: 800px;" rows="10" name="format" class="input-xxlarge" ${disabled}>${parameter.format!''}</textarea>
				<BR>
				<input class="btn btn-primary" type="button" value="json校验" onclick="formatJson('parameterFormat')" />
				<div>
					<span class="header-unit"><font color="red" id = 'parameterFormatDesc'>不选参数转换类，主要是时间格式化,<BR>选择参数转换类就是构造参数</font> </span>
				</div>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">是否必须:</label>
			<div class="controls">
				<#if parameter.required??>
					<label><input ${disabled} name="required" type="radio" value="true"<#if parameter.required>checked="checked"</#if> />是</label>
					<label><input ${disabled} name="required" type="radio" value="false"<#if !parameter.required>checked="checked"</#if> />否</label>
				<#else>
					<label><input ${disabled} name="required" type="radio" value="true"  />是</label>
					<label><input ${disabled} name="required" type="radio" value="false" checked="checked"/>否</label>
				</#if>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">是否是页码参数:</label>
			<div class="controls">
				<#if parameter.pageNum??>
					<label><input ${disabled} name="pageNum" type="radio" value="true"<#if parameter.pageNum>checked="checked"</#if> />是</label>
					<label><input ${disabled} name="pageNum" type="radio" value="false"<#if !parameter.pageNum>checked="checked"</#if> />否</label>
				<#else>
					<label><input ${disabled} name="pageNum" type="radio" value="true" />是</label>
					<label><input ${disabled} name="pageNum" type="radio" value="false" checked="checked"/>否</label>
				</#if>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">是否是页大小参数:</label>
			<div class="controls">
				<#if parameter.pageSize??>
					<label><input ${disabled} name="pageSize" type="radio" value="true"<#if parameter.pageSize>checked="checked"</#if> />是</label>
					<label><input ${disabled} name="pageSize" type="radio" value="false"<#if !parameter.pageSize>checked="checked"</#if> />否</label>
				<#else>
					<label><input ${disabled} name="pageSize" type="radio" value="true" />是</label>
					<label><input ${disabled} name="pageSize" type="radio" value="false" checked="checked"/>否</label>
				</#if>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">默认值:</label>
			<div class="controls">
				<textarea style="font-size: 15px; width: 800px;" rows="2" name="defaultValue" class="input-xxlarge" ${disabled}>${parameter.defaultValue!''}</textarea>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">表达式:</label>
			<div class="controls">
				<textarea style="font-size: 15px; width: 800px;" rows="2" name="expression" class="input-xxlarge" ${disabled}>${parameter.expression!''}</textarea>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label">下拉构建类:</label>
			<div class="controls">
				<select id="dropDownClass" name="dropDownClass" class="input-xxlarge" ${disabled} style="font-size: 15px; width: 800px;">
					<option value="">请选择...</option>
					<#list dropdownClassnames as classname>
						<option value="${classname}"  <#if parameter.dropDownClass?? && parameter.dropDownClass = classname> selected </#if> >${classname}</option>
					</#list>
				</select>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">下来选项值:</label>
			<div class="controls">
				<textarea id = "parameterDropDown" style="font-size: 15px; width: 800px;" rows="10" name="dropDown" class="input-xxlarge" ${disabled}>${parameter.dropDown!''}</textarea>
				<BR>
				<input class="btn btn-primary" type="button" value="json校验" onclick="formatJson('parameterDropDown')" />
                <div >
                    <span class="header-unit"><font color="red">不选下拉构建类，输入Map转json，key是参数值，value是展示的值,<BR>选择下拉构建类就是构造参数</font> </span>
                </div>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">排序:</label>
			<div class="controls">
				<input name="sort" value="<#if parameter.sort??> ${parameter.sort!''} <#else>0</#if>" maxlength="50"
					   class="required"  type="text" ${disabled}/>
			</div>
		</div>

		<input type="hidden" name="version" value="${parameter.version!''}"/>
		<div class="form-actions">
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="goback()" />&nbsp;
			<#if edit>
				<input id="btnReset" class="btn btn-primary" type="reset" value="重 置" onclick="resetForm()"/>&nbsp;
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存" />&nbsp;
			</#if>
		</div>
	</form>
</body>
</html>